'''
@文件    :views.py
@说明    :
@时间    :2020/04/05 16:04:04
@作者    :didiplus
@版本    :1.0
'''
from flask import Blueprint,request,make_response,json,jsonify
from .__init__ import *


search = Blueprint('search',__name__,url_prefix='/api/search')

@search.route('/default',methods=['POST','GET'])
def default():
    # 默认搜索关键词
    data = Send(url="/api/search/defaultkeyword/get", encrypt_method="eapi").POST(
        "http://interface3.music.163.com/eapi/search/defaultkeyword/get")   
    return make_response(jsonify(json.loads(data.text)),403)

@search.route('/suggest',methods=['POST','GET'])
def suggest():
    # 搜索建议
    query = request_query(request,
                          ["value", "s"],
                          ["type", {"type": "web"}])
    rtype = "web" if query.pop("type") == "web" else "keyword"
    data = Send(query).POST("weapi/search/suggest/"+rtype)
    return make_response(jsonify(json.loads(data.text)),403)

@search.route('/multimatch',methods=['POST','GET'])
def multimatch():
    # 搜索多重匹配
    query = request_query(request, ["type", {"type": 1}], ["value", {"s": ""}])
    data = Send(query).POST("weapi/search/suggest/multimatch")
    return make_response(jsonify(json.loads(data.text)),403)

@search.route('/hot',methods=['POST','GET'])
def hot():
    # 热搜列表(简略)
    query = {"type": 1111}
    data = Send(query).POST("weapi/search/hot", cookie={"ua": "mobile"})
    return make_response(jsonify(json.loads(data.text)),403)

@search.route('/hotdetail',methods=['POST','GET'])
def hotdetail():
    # 热搜列表(详细)
    data = Send().POST("weapi/hotsearchlist/get")
    return make_response(jsonify(json.loads(data.text)),403)
